<link rel="stylesheet" href="./css/frame2.css?v=1.0.1">
<div class="wrap" id="view" v-cloak>
    <ul class="u-wrap">
        <li class="list" v-for="(m, index) in ffList" @click="msg(m.id, m.name)">
            <div class="tx img-h">
                <img v-if="m.id == 1" src="./image/icon/ic_diantai.png" alt="">
                <img v-if="m.id == 2" src="./image/icon/ic_shenqing.png" alt="">
                <img v-if="m.id == 3" src="./image/icon/ic_shouyi.png" alt="">
                <img v-if="m.id == 4" src="./image/icon/ic_pingjia.png" alt="">
                <img v-if="m.id == 5" src="./image/icon/ic_mianju.png" alt="">
            </div>
            <div class="content">
                <div class="flex-bt">
                    <div class="name-wrap" style="position: relative;">
                        <span class="name">{{m.name}}</span>
                        <!-- <span class="yuan" v-if="m.num != 0"></span> -->
                    </div>
                    <span class="time">{{ m.time }}</span>
                </div>
                <!-- <p class="msg aui-ellipsis-1">{{m.content}}</p> -->
                <div class="flex-bt new-margin-t-10">
                    <p class="msg aui-ellipsis-1">{{clearHtml(m.content)}}</p>
                    <span class="yuan" v-if="m.num != 0">{{m.num>99?'99+':m.num}}</span>
                </div>
            </div>
        </li>
    </ul>
    <div id="no_more" :class="{'null': ffList.length == 0}"></div>
</div>
<script>
    var view = new Vue({
        el: '#view',
        data: {
            imgurl: imgurl,
            ffList: [],
            ffInfo: {},
        },
        methods: {
            // 清除html
            clearHtml: function(s){
                return clearHtml(s);
            },
            // 打开窗口
            msg: function (id, title) {
                var _this = this;
                // 电台 申请 收益 评价 系统通知
                var urlArr = ['frame2/dy_list', 'frame2/requestlist', 'frame2/imgsylist', 'frame2/evalist',
                    'frame2/sys_info'
                ];
                _ajax('Home/User/isread', function (ret, err) {
                    pushMsg(myuserid);
                    _url({ url: urlArr[id - 1], title: title });
                }, {
                    user_id: myuserid,
                    id: id
                })
            },
            _url: function (param, url) {
                _url(param, url);
            },
            // 图片自适应
            imgCss: function (url, event) {
                var e = event.currentTarget;
                imgCss(url, function (w, h) {
                    if (w < h) {
                        $(e).parent().addClass('img-w').removeClass('img-h');
                    }
                })
            },
        }
    })
    judgeLogin()
    openWS()

    // 获取消息列表
    function getMsgList() {
        _ajax('Home/User/syslist', function (ret, err) {
            _log(JSON.stringify(ret));
            _log(JSON.stringify(err));
            // if (ret && ret.code == 200) {
            //     view.ffList = ret.data;
            // }
        }, {
            user_id: myuserid
        })
    }

    function openWS() {
        // 建立长连接
        var _ws = new WS();
        _ws.open(function () {
            _ws.send(JSON.stringify({
                userid: myuserid
            }));

            getMsgList();
        });

        _ws.get(function (rets) {
            _log(rets)
            if (rets.indexOf('action') != -1) {
                rets = JSON.parse(rets);
                if(rets.code == 200){
                    if (rets.action == 'Home/Privatechat/getreadcount') {
                        getMsgList();
                        return;
                    }
                    if (rets.action == 'Home/User/syslist') {
                        view.ffList = rets.data;
                    }
                }
            }
        })
    }
</script>